package cn.jiahua.hospital.controller;

import cn.jiahua.hospital.dto.HotDoctor;
import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.dto.QuickDto;
import cn.jiahua.hospital.dto.Result;
import cn.jiahua.hospital.pojo.*;
import cn.jiahua.hospital.service.*;
import cn.jiahua.hospital.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags ="首页")
@RestController
@RequestMapping("/homePage/")
public class HomePageController {

    @Autowired
    AddressService AddressService;




    @Autowired
    HospitalService hospitalService;

    @Autowired
    NewsService newsService;

    @Autowired
    DoctorService doctorService;

    @Resource
    DepartmentsService departmentsService;

    @Resource
    IllnessService illnessService;

    @Resource
    HotDoctorService hotDoctorService;

    @Autowired
    QuickService quickService;

    @Autowired
    HospitalGradeService hospitalGradeService;

    @Autowired
    HospitalTypeService hospitalTypeService;
    //显示前6条新闻
    @ApiOperation(value = "显示新闻",produces = "application/json",notes = "显示前6条新闻")
    @GetMapping("/select/news")
    @ResponseBody
    public Result selectNews(){
        String newsTitle=null;
        String newsAuthor=null;
        Integer page=1;
        Integer limit=6;
        //调用service层获取数据w
        List<News> newsList=newsService.newsSelectPage(newsTitle,newsAuthor,(page-1)*limit,limit);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("newsList",newsList);
        return ResultUtils.returnSuccess("查询成功",map);
    }
    //显示地址
    @ApiOperation(value = "地区", produces = "application/json", notes = "显示所有地址")
    @GetMapping("/select")
    public Result select() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Address> addressList = AddressService.getAddressListByMap(map);
        return ResultUtils.returnDataSuccess(addressList);
    }

    //显示医院等级
    @ApiOperation(value = "医院等级", produces = "application/json", notes = "显示所有医院等级")
    @GetMapping("/grade/select")
    public Result gradeSelect() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<HospitalGrade> gradeList = hospitalGradeService.getHospitalGradeListByMap(map);
        return ResultUtils.returnDataSuccess(gradeList);
    }

    //显示医院类型
    @ApiOperation(value = "医院类型", produces = "application/json", notes = "显示所有医院类型")
    @GetMapping("/type/select")
    public Result typeSelect() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<HospitalType> typeList = hospitalTypeService.getHospitalTypeListByMap(map);
        return ResultUtils.returnDataSuccess(typeList);
    }
    //根据地址显示医院
    @ApiOperation(value = "医院所属地址", produces = "application/json", notes = "按地区医院列表")
    @ApiImplicitParam(name = "AddressId", value = "地址编号", required = true, dataType = "int")
    @GetMapping("/select/hospital")
    public Result selectHospital(Integer AddressId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("AddressId",AddressId);
        List<Hospital> hospitalList = hospitalService.getHospitalListByMap(map);
        return ResultUtils.returnDataSuccess(hospitalList);
    }

    @ApiOperation(value = "医生预约量", produces = "application/json", notes = "根据医生预约量排行")
    @GetMapping("/subscribeData/doctor")
    public Result subscribeDataDoctor() {
        int pageNO=1;
        int pageSize=5;
        List<Doctor> doctorList = doctorService.doctorSubscribeData((pageNO-1)*pageSize,pageSize);
        return ResultUtils.returnDataSuccess(doctorList);
    }

    @ApiOperation(value = "医院预约量", produces = "application/json", notes = "根据医院预约量排行")
    @GetMapping("/subscribeData/hospital")
    public Result subscribeDataHospital() {
        int pageNO=1;
        int pageSize=5;
        List<Hospital> hospitalList = hospitalService.hospitalAttentionData((pageNO-1)*pageSize,pageSize);
        return ResultUtils.returnDataSuccess(hospitalList);
    }

    @ApiOperation(value = "热门医院", produces = "application/json", notes = "显示热门医院")
    @GetMapping("/hot/hospital")
    public Result hotHospital() {
        int pageNO=1;
        int pageSize=10;
        List<Hospital> hospitalList = hospitalService.hospitalAttentionData((pageNO-1)*pageSize,pageSize);
        return ResultUtils.returnDataSuccess(hospitalList);
    }

    @ApiOperation(value = "首页医生", produces = "application/json", notes = "显示每个科室内预约量最多的医生")
    @GetMapping("/Home/doctor")
    public Result homeDoctor() {
        Map<String,Object> map =new HashMap<String,Object>();
        int pageNo=1;
        int pageSize=1;
        int roleId=0;
        for(int i=1;i<=5;i++){
            List<HotDoctor> hotDoctorsList=hotDoctorService.selectHotDoctor(i,(pageNo-1)*pageSize,pageSize,roleId);
            map.put("hotDoctors"+i,hotDoctorsList.get(0));
        }
        return ResultUtils.returnDataSuccess(map);
    }

    @ApiOperation(value = "热门医生", produces = "application/json", notes = "显示热门医生")
    @GetMapping("/hot/doctor")
    public Result hotDoctor() {
        int pageNo=1;
        int pageSize=10;
        int roleId=3;
        int i=0;
        List<HotDoctor> hotDoctorsList=hotDoctorService.selectHotDoctor(i,(pageNo-1)*pageSize,pageSize,roleId);
        return ResultUtils.returnDataSuccess(hotDoctorsList);




        
    }
    //快速预约（根据地区获取医院）
    @ApiOperation(value = "请选择医院", produces = "application/json", notes = "快速预约（根据地区获取医院）")
    @ApiImplicitParam(name = "AddressId", value = "地址编号", required = true, dataType = "int")
    @GetMapping("/quick/hospital")
    public Result quickHospital(Integer AddressId){
        List<QuickDto> quickDtoList=quickService.getQuickById(AddressId);
        return ResultUtils.returnDataSuccess(quickDtoList);
    }

    //快速预约（根据医院获取科室名称）
    @ApiOperation(value = "请输入科室名称", produces = "application/json", notes = "快速预约（根据医院获取科室名称）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "tdepartmentsName", value = "科室名称", required = false, dataType = "String")
    })
    @GetMapping("/quick/tdepartments")
    public Result quickTdepartments(Integer hospitalId,
                                    String tdepartmentsName){
        List<QuickDto> quickDtoList= quickService.getQuickTdepartments(hospitalId, tdepartmentsName);
        return ResultUtils.returnDataSuccess(quickDtoList);
    }

    //快速预约（根据医院和科室获取医生名称）
    @ApiOperation(value = "请输入医生名称", produces = "application/json", notes = "快速预约（根据医院和科室获取医生名称）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "tdepartmentsId", value = "科室ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "name", value = "医生名称", required = false, dataType = "String")
    })
    @GetMapping("/quick/name")
    public Result quickName(Integer hospitalId,
                            Integer tdepartmentsId,
                            String name){
        List<QuickDto> quickDtoList= quickService.getQuickName(hospitalId,tdepartmentsId,name);
        return ResultUtils.returnDataSuccess(quickDtoList);
    }

    //快速预约（搜索）
    @ApiOperation(value = "快速预约", produces = "application/json", notes = "快速预约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "tdepartmentsId", value = "科室ID", required = false, dataType = "int"),
            @ApiImplicitParam(name = "doctorId", value = "医生ID", required = false, dataType = "int")
    })
    @GetMapping("/quick/search")
    public Result quickSearch(Integer hospitalId,
                              Integer tdepartmentsId,
                              Integer doctorId){
        QuickDto quickDto= quickService.getQuick(hospitalId,tdepartmentsId,doctorId);
       return ResultUtils.returnDataSuccess(quickDto);
    }



    @ApiOperation(value = "热门科室", produces = "application/json", notes = "热门科室")
    @GetMapping("/hot/department")
    public Result getDepartmentName(){
        Map map = new HashMap();
        map.put("beginPos",0);
        map.put("pageSize",5);
        List list = departmentsService.getDepartmentsListByMap(map);

        return ResultUtils.returnDataSuccess(list);
    }


    @ApiOperation(value = "疾病所属", produces = "application/json", notes = "根据科室id查询后三个疾病")
    @ApiImplicitParam(value = "科室id",name = "departmentsId",required = false,dataType = "int")
    @GetMapping("/hot/illness")
    public Result getDepartmentId(Integer departmentsId){
        Map map = new HashMap();
        map.put("beginPos",0);
        map.put("pageSize",3);
        map.put("tdepartmentsId",departmentsId);
        List list = illnessService.getIllnessListByMap(map);

        return ResultUtils.returnDataSuccess(list);
    }



    @ApiOperation(value = "具体地区", produces = "application/json", notes = "根据id获取具体地区名")
    @ApiImplicitParam(value = "地区id",name = "id",required = false,dataType = "int")
    @GetMapping("/hot/department/{id}")
    public Result getDepartmentName(@PathVariable Integer id ){
        Map map = new HashMap();
        map.put("addressId",id);
        List<Address> list = AddressService.getAddressListByMap(map);
        return ResultUtils.returnDataSuccess(list);
    }
}